local wdtx__indulgenceSkill = fk.CreateSkill {
  name = "wdtx__indulgence_skill",
}


wdtx__indulgenceSkill:addEffect("cardskill", {
  name = "wdtx__indulgence_skill",
  prompt = "#wdtx__indulgence_skill",
  on_use = function(self,room, effect)
    local tos = effect.tos
    if #tos > 0 then
      local to = tos[1]
      local extra_reduce = effect.card:getMark("@indulgence_num")
      room:setPlayerMark(to,"@indulgence_num",extra_reduce)
    end
  end,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return user ~= to_select
  end,
  target_filter = function(self, player, to_select, selected, a, card)
    return #selected == 0 and self:modTargetFilter(to_select, selected, player, card, true)
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local to = effect.to
    local judge = {
      who = to,
      reason = "indulgence",
      pattern = ".|.|spade,club,diamond",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit ~= Card.Heart then
      to:skip(Player.Play)
    end
    local mark = to:getMark("@indulgence_num")
    if mark == 0 then
      self:onNullified(room, effect)
    else
      room:removePlayerMark(to,"@indulgence_num",1)
      room:moveCards{
        ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
        to = to,
        toArea = Card.PlayerJudge,
        moveReason = fk.ReasonJustMove,
        specialName = "self_draws" or "self_discs" or "self_cost",
      }
    end  
  end,
  on_nullified = function(self, room, effect)
    local to = effect.to
    local mark = to:getMark("@indulgence_num")
    if mark > 0 then
      room:setPlayerMark(to,"@indulgence_num",0)
    end 
    room:moveCards{
      ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonUse,
      specialName = "self_draws" or "self_discs" or "self_cost",
    }
  end,
})


return wdtx__indulgenceSkill